package com.niiwoo.civet.account.service.local.openAccount2.lanmao;

import com.niiwoo.civet.account.service.local.openAccount2.dto.CreateRequest;
import com.niiwoo.civet.account.service.local.openAccount2.dto.EnterpriseCreateRequest;
import com.niiwoo.civet.account.service.local.openAccount2.dto.EnterpriseRegisterOrder;
import com.niiwoo.civet.account.service.local.openAccount2.type.MockEnterpriseRegisterTypeable;
import com.niiwoo.tripod.lanmao.component.LanMaoGatewayService;
import com.niiwoo.tripod.lanmao.component.LanMaoSequence;
import com.niiwoo.tripod.lanmao.enums.BankCodeEnum;
import com.niiwoo.tripod.lanmao.enums.CredentialsTypeEnum;
import com.niiwoo.tripod.lanmao.enums.UserRoleEnum;
import com.niiwoo.tripod.lanmao.request.CompanyBindBankCardExpandRequest;
import com.niiwoo.tripod.lanmao.request.CompanyBindBankCardRegisterRequest;
import com.niiwoo.tripod.lanmao.response.LanMaoGatewayDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class EnterpriseRegisterLanMaoHandler implements OpenAccountLanMaoOperation<EnterpriseRegisterOrder>, MockEnterpriseRegisterTypeable {

    @Autowired
    private LanMaoGatewayService lanMaoGatewayService;

    @Autowired
    private LanMaoSequence lanMaoSequence;

    @Override
    public LanMaoGatewayDTO generateLanMaoGatewayDTO(CreateRequest request, EnterpriseRegisterOrder order) {
        EnterpriseCreateRequest enterpriseCreateRequest = (EnterpriseCreateRequest) request;
        CompanyBindBankCardExpandRequest companyBindBankCardExpandRequest = new CompanyBindBankCardExpandRequest();
        companyBindBankCardExpandRequest.setRequestNo(lanMaoSequence.getRequestNo());
        companyBindBankCardExpandRequest.setPlatformUserNo(enterpriseCreateRequest.getAccountNo());
        companyBindBankCardExpandRequest.setBankcardNo(enterpriseCreateRequest.getBankCardNo());
        companyBindBankCardExpandRequest.setBankcode(enterpriseCreateRequest.getBankCode());

        CompanyBindBankCardRegisterRequest companyBindBankCardRegisterRequest=new CompanyBindBankCardRegisterRequest();
        companyBindBankCardRegisterRequest.setEnterpriseName(order.getEnterpriseName());
        companyBindBankCardRegisterRequest.setBankLicense(order.getBankLicense());
        companyBindBankCardRegisterRequest.setOrgNo(order.getOrgNo());
        companyBindBankCardRegisterRequest.setBusinessLicense(order.getBusinessLicense());
        companyBindBankCardRegisterRequest.setTaxNo(order.getTaxNo());
        companyBindBankCardRegisterRequest.setUnifiedCode(order.getUnifiedCode());
        companyBindBankCardRegisterRequest.setCreditCode(order.getCreditCode());
        companyBindBankCardRegisterRequest.setLegal(order.getLegal());
        companyBindBankCardRegisterRequest.setIdCardType(CredentialsTypeEnum.enumOf(order.getIdCardType()));
        companyBindBankCardRegisterRequest.setLegalIdCardNo(order.getLegalIdCardNo());
        companyBindBankCardRegisterRequest.setContact(order.getContact());
        companyBindBankCardRegisterRequest.setContactPhone(order.getContactPhone());
        companyBindBankCardRegisterRequest.setUserRole(UserRoleEnum.BORROWERS);
        companyBindBankCardRegisterRequest.setBankcardNo(order.getBankcardNo());
        companyBindBankCardRegisterRequest.setBankcode(BankCodeEnum.enumOf(order.getBankcode()));
        companyBindBankCardRegisterRequest.setAuthList(order.getAuthList());

        return lanMaoGatewayService.companyBindBankCardRegister(companyBindBankCardRegisterRequest);
    }


}
